package com.scqzy.shengchunqiang.sword2offer.day05;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @Description: 剑指 Offer 50. 第一个只出现一次的字符
 * @Author 盛春强
 * @Date 2021/8/12 20:53
 */
public class FirstUniqChar {
    public char firstUniqChar(String s) {
        Map<Character,Integer> map = new LinkedHashMap<>();
        for (char c : s.toCharArray()) {
            map.put(c,map.getOrDefault(c,0)+1);
        }
        for (Map.Entry<Character, Integer> e : map.entrySet()) {
            if (e.getValue() == 1) {
                return e.getKey();
            }
        }
        return ' ';
    }
}
